/**
 * @(#)XiaoYouMan.java, 2015年4月1日. Copyright 2012 Yodao, Inc.
 * All rights reserved. YODAO
 * PROPRIETARY/CONFIDENTIAL. Use is subject
 * to license terms.
 */
package com.scitc.pleasurevideo.data;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * contradiction
 */
public class ETMan {

    private static ETMan etMan;

    static {
        etMan = new ETMan();
    }

    private ETMan() {
    }

    public static ETMan getMananger() {
        return etMan;
    }

    private Gson mGson;

    public synchronized Gson getGson() {
        if (mGson == null)
            // 不转换没有 @Expose 注解的字段
            mGson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
                    .create();
        return mGson;
    }

    public static void savePref(Context context, String key, String value) {
        SharedPreferences.Editor editor = SharedPreferencesHelper.getSharedPreferences(context).edit();
        editor.putString(key, value);
        editor.commit();
    }

    public static String getPref(Context context, String key, String value) {
        String value1 = SharedPreferencesHelper.getSharedPreferences(context).getString(key, value);
        if (TextUtils.isEmpty(value1) || value1.equals(value)) {
            value1 = SharedPreferencesHelper.getOldSharedPreferences(context).getString(key, value);
        }
        return value1;
    }

    public static void savePref(Context context, String key, Long value) {
        SharedPreferences.Editor editor = SharedPreferencesHelper.getSharedPreferences(context).edit();
        editor.putLong(key, value);
        editor.commit();
    }

    public static void removePref(Context context, String key) {
        SharedPreferences.Editor editor = SharedPreferencesHelper.getSharedPreferences(context).edit();
        editor.remove(key);
        editor.commit();
        SharedPreferences.Editor editor1 = SharedPreferencesHelper.getOldSharedPreferences(context).edit();
        editor1.remove(key);
        editor1.commit();
    }

    public static Long getPref(Context context, String key, Long value) {
        return SharedPreferencesHelper.getSharedPreferences(context).getLong(key, value);
    }

    public static void savePref(Context context, String key, Integer value) {
        SharedPreferences.Editor editor = SharedPreferencesHelper.getSharedPreferences(context).edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public static Integer getPref(Context context, String key, Integer value) {
        Integer value1 = SharedPreferencesHelper.getSharedPreferences(context).getInt(key, value);
        if (value1 == value) {
            value1 = SharedPreferencesHelper.getOldSharedPreferences(context).getInt(key, value);
        }
        return value1;
    }

    public static void savePref(Context context, String key, boolean value) {
        SharedPreferences.Editor editor = SharedPreferencesHelper.getSharedPreferences(context).edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public static boolean getPref(Context context, String key, boolean value) {
        return SharedPreferencesHelper.getSharedPreferences(context).getBoolean(key, value);
    }

}
